<template>

  <div class="box"><router-link to="/My">
    <van-nav-bar
  title="登录"
  left-arrow
/></router-link>
<!-- 手机号 -->
<van-form @submit="onSubmit">
  <van-field
    v-model="username"
    name="账号"
    label="账号"
    placeholder="账号"
    :rules="[{ required: true, message: '请填写账号' }]"
  />
  <van-field
    v-model="password"
    type="password"
    name="密码"
    label="密码"
    placeholder="密码"
    :rules="[{ required: true, message: '请填写密码' }]"
    
  />
 
  <p class="login"><router-link to="/Logins">注册账号</router-link> </p>
  
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" color="pink" @click="registers">登录</van-button>
  </div>
</van-form>

  


  </div>
</template>

<script>
import {setToken} from '@/api/articleApl'
import { Toast } from 'vant';
export default {
  
  data(){
      return{
          sms:'',
          tel: '',
          btn:'60',
          username: '',
          password: '',
         token:''
      }
  },
methods: {
    onSubmit(values) {
      console.log('submit', values);
    },
    onClickLeft() {
      Toast('返回');
    },
    onClickRight() {
      Toast('按钮');
    },
    // 登录点击事件
    registers(){

       
         this.$http.post('/user/login',{
            username:this.username,
            password:this.password
         })
        .then(res=>{
            console.log(res);
            this.token = res.data.token
            setToken(this.token)
            this.$http.post('/user/getuserInfo',{
              token:this.token
            })
            .then((res)=>{
              console.log(res.data);
              localStorage.setItem('user',JSON.stringify(res.data))
              localStorage.setItem('Token',JSON.stringify(res.data.userInfo))
              this.$router.push('/My')
            })
        })
    },
   
    // getuserInfo(){
      
    //      this.$http.post('/user/UserInfo',{
    //         token:this.token
    //      })
    //     .then(res=>{
    //         console.log(res);
    //         // localStorage.setItem('user',(res.data))
    //         // let unserInfo = JSON.stringify(res.userInfo)
    //         // localStorage.setItem('Token',unserInfo)
    //         // this.$router.push('/My')
    //     })   
    // }
      
    
  },
}
</script>

<style lang="less" scoped>
.box{
    height: 100vh;
        position: relative;
        z-index: 9;
        background-color: #fff;
}
.shouji{
  display: flex;
}
.shouji .iconfont {
  display: inline-block;
  margin-right: -10px ;
  z-index: 1;
  margin-left: 15px;
  height: 50px;
  line-height: 40px;
}
.boder{
  margin-right:10px ; 
}
.auth{
  display: flex;
}
.auth .iconfont {
   display: inline-block;
  margin-right: -10px ;
  z-index: 1;
  margin-left: 15px;
  height: 50px;
  line-height: 48px;
 
}
.register{
  
    margin-top: 50px ;
    background-color: pink;
    width: 300px;
    height: 50px;
}
.login{
  float: left;
  margin-left: 20px;
}
</style>